﻿@using Webdiyer.WebControls.Mvc;
@using Ec_System.Models.Web;
@using Ec_System.Facade.Web;

@model PagedList<ItemOrderData>


@{
    Layout = null;
    var imageServer = new SiteConfigFacade().ImageServer;
}

<div class="AreaR2">
    <div class="box">
        <div class="box_1">
            <div class="userCenterBox boxCenterList clearfix" style="_height:1%;">

                <h5>
                    <span>订单列表</span>
                    <span><a href="/UserCenter/GetCustomerOrderHistoryByLoginID/id"> 历史订单</a></span>
                </h5>
                <div class="blank"></div>
                @for (int i = 0; i < Model.Count; i = i + 1)
                {
                    <div style="border-top:1px;border-left:1px;border-right:1px;border-bottom:0px;border-style:solid;border-color:#808080;text-align:left;height:38px;background-color:#e1ddd5;vertical-align:middle">
                        <span style="font-size:16px;vertical-align:middle">
                            @Model[i].InDate &nbsp;
                            订单编号：<b>@Model[i].OrderId</b> &nbsp;
                            订单状态：@Model[i].ShowOrderStatus &nbsp;
                            订单金额：@Model[i].FactMoney.ToString("C") &nbsp;
                            节省：@Model[i].Discount.ToString("C")  &nbsp;&nbsp;
                            @if (DateTime.Now < ((DateTime)Model[i].InDate).AddDays(7) && Model[i].OrderStatus != 3)
                            {
                                <a href="/UserCenter/AddComplaint?orderID=@Model[i].OrderId"> 投诉</a>
                            }
                        </span>
                    </div>
                    <table width="100%" cellpadding="5" cellspacing="0" border="0" align="center">
                        <tr style="height:40px; border-style: solid; border-width: 1px; border-color: #f6f5f6; background-color: #f6f5f5;">
                            <td align="center" valign="middle" colspan="2">商品</td>
                            <td align="center" valign="middle" width="60">价格</td>
                            <td align="center" valign="middle" width="60">数量</td>
                            <td align="center" valign="middle" width="60">单位</td>
                            <td align="center" valign="middle" width="60">金额</td>
                            <td align="center" valign="middle" width="60">状态</td>
                            <td align="center" valign="middle" width="120" colspan="3">操作</td>
                        </tr>
                        @for (int n = 0; n < Model[i].ItemDatailsList.Count; n++)
                        {
                            <tr>
                                <td align="left" valign="middle" width="85">
                                    <a href="/Item/@Model[i].ItemDatailsList[n].ProductID">
                                        <img src="@imageServer/product/800800/@{@Model[i].ItemDatailsList[n].ImageUrl} " width="80" height="80" />
                                    </a>
                                </td>
                                <td align="left" valign="middle">
                                    <a href="/Item/@Model[i].ItemDatailsList[n].ProductID">
                                        @Model[i].ItemDatailsList[n].ShopProductTitle
                                    </a><br />
                                    <a href="/Item/@Model[i].ItemDatailsList[n].ProductID">
                                        @Model[i].ItemDatailsList[n].SecondTitle
                                    </a>
                                </td>
                                <td align="center" valign="middle">
                                    @Model[i].ItemDatailsList[n].UnitPrice.ToString("C")
                                </td>
                                <td align="center" valign="middle">
                                    @Model[i].ItemDatailsList[n].Count
                                </td>
                                <td align="center" valign="middle">
                                    @Model[i].ItemDatailsList[n].Unit
                                </td>
                                <td align="center" valign="middle">
                                    @*@Model[i].ItemDatailsList[n].FactMoney.ToString("C")*@
                                </td>
                                <td align="center" valign="middle">
                                    <span id="spanReturnMark@{@Model[i].ItemDatailsList[n].ID}">@Model[i].ItemDatailsList[n].ShowReturnMark</span>
                                </td>
                                <td align="center" valign="middle" width="60">
                                    <a href="/Item/@Model[i].ItemDatailsList[n].ProductID" target="_blank">再次购买</a>
                                </td>
                                <td align="center" valign="middle" width="60">
                                    @if (DateTime.Now < ((DateTime)Model[i].InDate).AddDays(3) && Model[i].OrderStatus != 3)
                                    {
                                        <span id="btn_return@{@Model[i].ItemDatailsList[n].ID}" style="visibility: @Model[i].ItemDatailsList[n].BtnReApplyStyle"
                                              onclick="ShowDiv('divWindow','@Model[i].ItemDatailsList[n].OrderId','@Model[i].ItemDatailsList[n].OrderDetailId','@Model[i].VendorNumber','@Model[i].ItemDatailsList[n].ID')">申请退货</span>
    }
                                </td>
                                <td>
                                    @if (Model[i].OrderStatus == 3)
                                    {
                                        if (Model[i].ItemDatailsList[n].IsEvaluation > 0)
                                        {
                                            <span>已经评价</span>
                                        }
                                        else if (DateTime.Now > ((DateTime)Model[i].InDate).AddDays(7))
                                        {
                                            <span>系统评价</span>
                                        }
                                        else
                                        {
                                            <a href="/UserCenter/UserEvaluation?orderID=@Model[i].OrderId&productID=@Model[i].ItemDatailsList[n].ProductID">请评价</a>
                                        }
                                    }
                                </td>
                            </tr>
    }
                    </table>
    }
            </div>
        </div>
        @*<div><hgroup>  @Html.Pager(Model, new PagerOptions { PageIndexParameterName = "id", ShowGoButton = false, AlwaysShowFirstLastPageNumber = true })</hgroup></div>    </div>*@
    
</div>
<div class="blank"></div>


<!--弹出窗口:Begin-->
<div id="divWindow" class="popCss" style="height:240px;">

    <div style="background-color: #A31313; height: 28px; text-align: right">
        <span style="color:white;vertical-align:middle" onclick="CloseDiv('divWindow', 'fade')">关闭</span>&nbsp;
    </div>
    <div style="padding-left:10px;">
        <div>主订单号：<span id="orderId"></span></div>
        <div>订单明细号：<span id="orderDetailId"></span></div>
        <div>退货理由：<br><textarea id="txt_reason" rows="6" cols="30"></textarea></div>
        <a onclick="Approve('Y')" id="btn_ApplyReturn">提交申请</a>&nbsp;&nbsp;
        <input type="hidden" id="hbtnId" value="" /> @*将审批按钮的ID传过来暂存*@
        <input type="hidden" id="hvendorNumver" value="" />
        <div id="msg"></div>
    </div>
</div>
<!--弹出窗口:End-->
<script type="text/javascript">
    //弹出隐藏层
    function ShowDiv(show_div, orderId, orderDetailId, vendorNumber, btnId) {
        $("#hbtnId").val(btnId);
        $("#hvendorNumver").val(vendorNumber);
        $("#orderId").html(orderId);
        $("#orderDetailId").html(orderDetailId);
        $("#" + show_div).fadeIn("slow");

        //获取页面文档的高度
        var docheight = $(document).height();
        //追加一个层，使背景变灰
        $("body").append("<div id='greybackground'></div>");
        $("#greybackground").css({ "opacity": "0.5", "background": "gray", "height": docheight });
    };
    //关闭弹出层
    function CloseDiv(show_div) {
        $("#greybackground").remove();
        $("#" + show_div).fadeOut("slow");
    };

    function Approve(v) {
        $("#btn_ApplyReturn").attr("disabled", "disabled");
        if ($("#txt_reason").val() == '') {
            $("#msg").html("<font color=red>请输入申请退货原因!</font>");
            $("#btn_ApplyReturn").removeAttr("disabled");
            return;
        }
        $.post("/UserCenter/ApplyReturnOrder",
            {
                orderID: $("#orderId").html(),
                orderDetailsID: $("#orderDetailId").html(),
                vendorNumber: $("#hvendorNumver").val(),
                reason: $("#txt_reason").val()
            },
            function (returnValue) {
                $("#btn_ApplyReturn").removeAttr("disabled");;
                if (returnValue.ResultBool == true) {
                    var btnId = $("#hbtnId").val();
                    $("#btn_return" + btnId).remove();
                    $("#spanReturnMark" + btnId).text('正在处理');
                    //$("#msg").html("<font color=red>退货申请提交成功!</font>");
                    $("#greybackground").remove();
                    $("#divWindow").fadeOut("slow");
                    window.parent.alert("退货申请提交成功！");
                }
                else {
                    $("#msg").html("<font color=red>操作失败，请检查后重试!</font>");
                }
            }, "json")
    }
</script>

